import pygame, math, sys, time

class Screen():
    
    def __init__(self, imgs, pos):
        self.images = []
        self.frame = 0
        for img in imgs:
            surf = pygame.image.load(img)
            self.images += [surf]
            
        self.image = self.images[self.frame]
        self.rect = self.image.get_rect()
        self.place(pos)
        self.waitCount = 1
        self.waitMax = 10000
        self.upframe = True
        
    def place(self, pt):
        self.rect = self.rect.move(pt)
        
        
    def animate(self, waitTime, cycle = True, place = False, wave = False):
        self.maxFrame = len(self.images)-1
        if self.waitCount <= waitTime:
            self.waitCount += 1
        else:
            self.waitCount = 0
            if cycle:
                if self.frame > len(self.images)-1:
                    self.frame = len(self.images)-1

                if self.frame == len(self.images)-1:
                    self.frame = 0
                else:
                    self.frame += 1
                            
                self.image = self.images[self.frame] 
                
            elif not cycle: 
                if self.frame < self.maxFrame:
                    self.frame += 1
                else:
                    pass
               
            elif wave:
                if self.frame < self.maxFrame and self.upFrame:
                    self.frame += 1
                elif self.frame >= self.maxFrame:
                    self.frame += -1
                    self.upFrame = False
                elif self.frame == 0:
                    self.upFrame = True
                    
            self.image = self.images[self.frame]
            
    
        